<?php

use think\migration\Migrator;
use think\migration\db\Column;

/**
 * 系统菜单迁移类
 * Class SystemMenus
 */
class SystemMenus extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('system_menus', ['comment' => '系统菜单表', 'engine' => 'InnoDB']);
        $table->addColumn('pid', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '父级 ID'])
            ->addColumn('icon', 'string', ['limit' => 16, 'default' => '', 'comment' => '图标'])
            ->addColumn('name', 'string', ['limit' => 32, 'default' => '', 'comment' => '名称'])
            ->addColumn('module', 'string', ['limit' => 32, 'default' => '', 'comment' => '模块名'])
            ->addColumn('controller', 'string', ['limit' => 64, 'default' => '', 'comment' => '控制器名'])
            ->addColumn('action', 'string', ['limit' => 32, 'default' => '', 'comment' => '方法名'])
            ->addColumn('params', 'string', ['limit' => 128, 'default' => '', 'comment' => '参数'])
            ->addColumn('sort', 'tinyint', ['limit' => 3, 'default' => 0, 'comment' => '排序'])
            ->addColumn('is_show', 'tinyint', ['limit' => 1, 'default' => 1, 'comment' => '是否显示'])
            ->addIndex(['pid', 'is_show'])
            ->create();
    }
}
